package com.lw.netty.websocket;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.time.LocalDateTime;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/4/25 11:44
 */
public class MyWebsocketHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame textWebSocketFrame) throws Exception {
        System.err.println("MyWebsocketHandler中的channelRead0方法执行了");
        String text = textWebSocketFrame.text();
        System.err.println(text);
        //发送数据
        channelHandlerContext.writeAndFlush(new TextWebSocketFrame("我与"+ LocalDateTime.now()+"收到了你的消息，内容是===>"+text));
    }

}
